unit cx_vars;
interface
                             {}
uses
 Windows,
 m_api, m_globaldefs, Classes, cx_procs;

const
    piShortName = 'ExchangeRates';
    piVersion   = $00030006;
    piDescription =  'This plugin shows exchange rates for chosen currencies in the contact list.';
    piAuthor = 'Konstantin Shramchevsky, Alexander Kornienko';
    piauthorEmail = 'pluto@guitarplayer.ru, korneysan@mail.ru';
    picopyright = '(c) 2009 Konstantin Shramchevsky, Alexander Kornienko';
    pihomepage = 'http://miranda-icq.sourceforge.net/';
    piisTransient = 0;
    pireplacesDefaultModule = 0;
    opt_UserDefaultGroup: PChar = 'user/defaultgroup';
    //
    cx_ConnectionDescription = piShortName+' data connection';
    //
    cx_menu_UpdateRates = '&Update exchanges';
    cx_menu_UpdateStop = 'Stop exchange update';
    cx_menu_UpdateRate = '&Update rate';


    cx_Nick : PChar = 'Nick';
    cx_Source : PChar = 'Source';
    cx_StateIn : PChar = 'StateIn';
    cx_ComingRate   : PChar = 'ComingRate';
    cx_PreviousRate   : PChar = 'PreviousRate';
    cx_CurrentRate   : PChar = 'CurrentRate';
    cx_LastUpdate    : PChar = 'LastUpdate';
    cx_ComingDate   : PChar = 'ComingDate';
    cx_PreviousDate   : PChar = 'PreviousDate';
    cx_CurrentDate   : PChar = 'CurrentDate';
    cx_ContactStatus : PChar = 'Status';
    cx_Country        : PChar = 'Country';

    cx_ID     : PChar = 'ID';
    cx_Currency : PChar = 'Currency';
    cx_Amount : PChar = 'Amount';
    //
    cx_id_Name     = $0001;
    cx_id_Amount   = $0002;
    cx_id_Currency = $0004;
    cx_id_StateIn  = $0008;
    cx_id_Source   = $0010;
    cx_id_Current  = $0020;
    cx_id_CC       = $0040; //0.3.0.6
    cx_id_SM       = $0080; //0.3.0.6
    cx_id_All      = $00FF;
    cx_id_Delete   = $FFFF;

    cx_opt_OptsExist : PChar = 'OptionsExist';
    cx_opt_ContactCaption : PChar = 'ContactCaption';
    cx_opt_StatusMessage : PChar = 'StatusMessage';
    cx_opt_HistoryLog : PChar = 'HistoryLog';
    cx_opt_RefreshInterval  : PChar = 'RefreshInterval';
    cx_opt_Precision  : PChar = 'Precision';
    cx_opt_Unavailable : PChar = 'Unavailable';

    cx_lst_Del = 'Delete on Apply';
    cx_dlg_NewCaption = 'New rate';
    cx_err_Exists = 'This rate already exists!';
    cx_dlg_DeleteCaption = 'Delete rate';
    cx_dlg_DeleteSure = 'Are you sure to delete this %s/%s (from %s) rate?';
    cx_err_NoSame = 'No conversion to the same currency!';
    cx_dlg_ChangeCaption = 'Change rate';

    //default values
    cx_ContactCaptionDef = '%a %f = %s %t';
    cx_StatusMessageDef = '%c (%l)';
    cx_HistoryLogDef = '%d: 1 %f = %r %t   %a %f = %s %t';
    IntervalDefault = 600;
    PrecisionDefault = 2;
    UnavailableDef = 'N/A';
    //
    cx_txt_am  = 'Amount of currency';
    cx_txt_sc  = 'Source currency';
    cx_txt_dc  = 'Destination currency';
    cx_txt_cr  = 'Current rate between source and destination currency, 1/1';
    cx_txt_cra = 'Current rate between source and destination currency, by amount';
    cx_txt_pr  = 'Previous rate between source and destination currency, 1/1';
    cx_txt_pra = 'Previous rate between source and destination currency, by amount';
    cx_txt_ur  = 'Upcoming rate between source and destination currency, 1/1 (where applicable)';
    cx_txt_ura = 'Upcoming rate between source and destination currency, by amount (where applicable)';
    cx_txt_dt  = 'Date and time of last update';
    cx_txt_rs  = 'Rate source';


type
  ICurrency = record
    ID  : Integer;
    //Name : PChar;
    Name: String;
    Amount : Integer;
    Currency : String;
    StateIn : String;
    //Source : PChar;
    Source : String;
    CurrentRate : string;
    hContact : THandle;
    Changes: Integer;
    //0.3.0.6
    CC: String;
    SM: String;
  end;

  ICurrencyList = array of ICurrency;

  TRate = record
    rate : real;
    date : TDateTime;
  end;

  TRates = Record
    coming : TRate;
    current : TRate;
    previous : TRate;
    success : boolean;
  end;

var
    cx_hkModulesLoad,
    cx_hkOptInitialise,
    cx_hkOnContactMenu,
    cx_hContactMenuItem,
    cx_hkOnMainMenu,
    cx_hMainMenuItem: THandle;
    cx_Clist  : ICurrencyList;
    cx_DateFromStr, cx_DateToStr, cx_TodayStr, cx_TomorrowStr: String;
    cx_DateFrom, cx_DateTo, cx_Today, cx_Tomorrow: TDateTime;
    cx_Status : Integer = ID_STATUS_OFFLINE;
    cx_StatusPrevious: Integer = ID_STATUS_OFFLINE;
    ThreadUpdate : TThreadUpdate = nil;
    cx_MenuIcon : THandle = 0;
    cx_hNetLibUser : THandle = 0;
    PrecisionValue : Integer = PrecisionDefault;
    cx_UnavailableText: String = UnavailableDef;
    //
    {
    cx_IsFlags: Boolean = false;
    cx_hHookExtraRebuild: THandle;
    cx_hHookExtraApply: THandle;
    }

function IsContactProto(hContact: THandle; const szProto: PAnsiChar): int;
procedure ClearRates(var ARates: TRates);

implementation
uses
 DateUtils;

//MS_PROTO_ISPROTOONCONTACT helper
function IsContactProto(hContact: THandle; const szProto: PAnsiChar): int;
begin
 Result := PluginLink^.CallService(MS_PROTO_ISPROTOONCONTACT, wParam(hContact), lParam(szProto));
end;

procedure ClearRates(var ARates: TRates);
begin
 ARates.coming.rate:=0;
 ARates.coming.date:=Tomorrow;
 ARates.current.rate:=0;
 ARates.current.date:=Today;
 ARates.previous.rate:=0;
 ARates.previous.date:=Yesterday;
 ARates.success:=false;
end;


end.
